package org.railage.client.beans;

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.apache.log4j.Logger;
import org.railage.common.dto.ScheduleRecordDTO;
import org.railage.server.services.ScheduleService;
import org.railage.server.services.StationService;

@ManagedBean(name = "schedule")
@ViewScoped
public class ScheduleBean {
	
	private static final Logger log = Logger.getLogger(ScheduleBean.class);
	
	private StationService stationService = new StationService();
	private ScheduleService scheduleService = new ScheduleService();
	
	private String selectedStation = null;
	private String[] stations;
	
	private List<ScheduleRecordDTO> scheduleRecords = null;
	private ScheduleRecordDTO selectedRecord = null;
	
	public ScheduleBean() {
		stations = stationService.getStationNames(null);
	}
	
	public void stationChanged() {
		log.debug("Station: " + selectedStation);
		scheduleRecords = Arrays.asList(scheduleService.getSchedule(selectedStation));
	}

	public String[] getStations() {
		return stations;
	}

	public String getSelectedStation() {
		return selectedStation;
	}

	public void setSelectedStation(String selectedStation) {
		this.selectedStation = selectedStation;
	}

	public List<ScheduleRecordDTO> getScheduleRecords() {
		return scheduleRecords;
	}

	public void setScheduleRecords(List<ScheduleRecordDTO> scheduleRecords) {
		this.scheduleRecords = scheduleRecords;
	}

	public ScheduleRecordDTO getSelectedRecord() {
		return selectedRecord;
	}

	public void setSelectedRecord(ScheduleRecordDTO selectedRecord) {
		this.selectedRecord = selectedRecord;
	}

	
	
}
